home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 April / Software of the Month Club 1996 April.iso / pc / os2 / psutils / src / includ~1.pl < prev    next >
Text File  |  1996-02-21  |  1KB  |  47 lines

  1. @PERL@
  2. # includeres: include resources in PostScript file
  3. #
  4. # Copyright (C) Angus J. C. Duggan 1991-1995
  5. # See file LICENSE for details.
  6.  
  7. $prog = ($0 =~ s=.*/==);
  8.  
  9. %extn = ("font", ".pfa", "file", ".ps", "procset", ".ps", # resource extns
  10.      "pattern", ".pat", "form", ".frm", "encoding", ".enc");
  11. %type = ("%%BeginFile:", "file", "%%BeginProcSet:", "procset",
  12.      "%%BeginFont:", "font"); # resource types
  13.  
  14. sub filename {            # make filename for resource in @_
  15.    local($name);
  16.    foreach (@_) {        # sanitise name
  17.       s/[!()\$\#*&\\\|\`\'\"\~\{\}\[\]\<\>\?]//g;
  18.       $name .= $_;
  19.    }
  20.    $name =~ s@.*/@@;        # drop directories
  21.    die "Filename not found for resource ", join(" ", @_), "\n"
  22.       if $name =~ /^$/;
  23.    $name;
  24. }
  25.  
  26. while (<>) {
  27.    if (/^%%IncludeResource:/ || /^%%IncludeFont:/ || /^%%IncludeProcSet:/) {
  28.       local($comment, @res) = split(/\s+/);
  29.       local($type) = defined($type{$comment}) ? $type{$comment} : shift(@res);
  30.       local($name) = &filename(@res);
  31.       local($inc) = "@INCLUDE@"; # system include directory
  32.       if (open(RES, $name) || open(RES, "$name$extn{$type}") ||
  33.       open(RES, "$inc/$name") || open(RES, "$inc/$name$extn{$type}")) {
  34.      while (<RES>) {
  35.         print $_;
  36.      }
  37.      close(RES);
  38.       } else {
  39.      print "%%IncludeResource: ", join(" ", $type, @res), "\n";
  40.      print STDERR "Resource $name not found\n";
  41.       }
  42.    } else {
  43.       print $_;
  44.    }
  45. }
  46. @END@
  47.